package model;

import com.fasterxml.jackson.annotation.JsonInclude;
import enums.BaseRespCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * @author: Jacky Chai
 * @date: 2019/4/19
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PageResponse<T> extends BaseObject implements Serializable {

    private static final long serialVersionUID = -1013991394945313492L;

    @ApiModelProperty(value = "响应码", required = true)
    private int code;
    /**
     * 提示信息
     */
    @ApiModelProperty(value = "提示信息", required = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String msg;
    @ApiModelProperty(value = "业务相应数据", required = true)
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private PageResult<T> result;

    /**
     * 签名串
     */
    @ApiModelProperty(value = "签名，只有面向第三方的接口有")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String sign;

    public PageResponse() {

    }

    public PageResponse(PageResult<T> pageResult) {
        this(BaseRespCodeEnum.SUC.getCode(), BaseRespCodeEnum.SUC.getMsg(), pageResult);
    }

    public PageResponse(int code, String msg, PageResult pageResult) {
        this.result = pageResult;
        this.code = code;
        this.msg = msg;
    }

    public PageResponse(int code, String msg) {
        this(code, msg, null);
    }

    public PageResponse(List<T> data, PageInfo pageInfo) {
        this(new PageResult<>(pageInfo, data));
    }

    public PageResponse(List<T> data, int pageNo, int pageSize, int totalCount) {
        this(new PageResult<>(new PageInfo(pageNo, pageSize, totalCount), data));
    }
}
